/*      */ package com.zimbra.cs.account;
/*      */ 
/*      */ import com.google.common.base.Strings;
/*      */ import com.sun.mail.smtp.SMTPMessage;
/*      */ import com.zimbra.common.account.Key.AccountBy;
/*      */ import com.zimbra.common.account.Key.CosBy;
/*      */ import com.zimbra.common.account.Key.DistributionListBy;
/*      */ import com.zimbra.common.account.Key.DomainBy;
/*      */ import com.zimbra.common.account.ZAttrProvisioning.AccountStatus;
/*      */ import com.zimbra.common.mime.shim.JavaMailInternetAddress;
/*      */ import com.zimbra.common.service.ServiceException;
/*      */ import com.zimbra.common.soap.Element;
/*      */ import com.zimbra.common.soap.MailConstants.ShareConstants;
/*      */ import com.zimbra.common.soap.SoapProtocol;
/*      */ import com.zimbra.common.util.BlobMetaData;
/*      */ import com.zimbra.common.util.L10nUtil;
/*      */ import com.zimbra.common.util.L10nUtil.MsgKey;
/*      */ import com.zimbra.common.util.Log;
/*      */ import com.zimbra.common.util.Pair;
/*      */ import com.zimbra.common.util.StringUtil;
/*      */ import com.zimbra.common.util.ZimbraLog;
/*      */ import com.zimbra.common.zmime.ZMimeBodyPart;
/*      */ import com.zimbra.common.zmime.ZMimeMultipart;
/*      */ import com.zimbra.cs.ldap.ZLdapFilterFactory;
/*      */ import com.zimbra.cs.mailbox.ACL;
/*      */ import com.zimbra.cs.mailbox.ACL.Grant;
/*      */ import com.zimbra.cs.mailbox.Folder;
/*      */ import com.zimbra.cs.mailbox.MailItem.Type;
/*      */ import com.zimbra.cs.mailbox.Mailbox;
/*      */ import com.zimbra.cs.mailbox.Mailbox.FolderNode;
/*      */ import com.zimbra.cs.mailbox.MailboxLock;
/*      */ import com.zimbra.cs.mailbox.MailboxManager;
/*      */ import com.zimbra.cs.mailbox.MetadataList;
/*      */ import com.zimbra.cs.mailbox.Mountpoint;
/*      */ import com.zimbra.cs.mailbox.OperationContext;
/*      */ import com.zimbra.cs.mailbox.acl.AclPushSerializer;
/*      */ import com.zimbra.cs.servlet.ZimbraServlet;
/*      */ import com.zimbra.cs.util.AccountUtil;
/*      */ import com.zimbra.cs.util.JMSession;
/*      */ import com.zimbra.soap.mail.message.SendShareNotificationRequest.Action;
/*      */ import java.io.ByteArrayInputStream;
/*      */ import java.io.ByteArrayOutputStream;
/*      */ import java.io.IOException;
/*      */ import java.io.InputStream;
/*      */ import java.io.OutputStream;
/*      */ import java.io.OutputStreamWriter;
/*      */ import java.util.ArrayList;
/*      */ import java.util.Date;
/*      */ import java.util.HashMap;
/*      */ import java.util.HashSet;
/*      */ import java.util.LinkedList;
/*      */ import java.util.List;
/*      */ import java.util.Locale;
/*      */ import java.util.Map;
/*      */ import java.util.Set;
/*      */ import javax.activation.DataHandler;
/*      */ import javax.activation.DataSource;
/*      */ import javax.mail.Address;
/*      */ import javax.mail.Message.RecipientType;
/*      */ import javax.mail.MessagingException;
/*      */ import javax.mail.Transport;
/*      */ import javax.mail.internet.AddressException;
/*      */ import javax.mail.internet.InternetAddress;
/*      */ import javax.mail.internet.MimeBodyPart;
/*      */ import javax.mail.internet.MimeMultipart;
/*      */ import org.apache.commons.codec.binary.Hex;
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ public class ShareInfo
/*      */ {
/*      */   protected ShareInfoData mData;
/*      */   protected MetadataList mGrants;
/*      */   
/*      */   public ShareInfo()
/*      */   {
/*  112 */     this.mData = new ShareInfoData();
/*      */   }
/*      */   
/*      */   public boolean hasGrant() {
/*  116 */     return this.mGrants != null;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private static boolean matchesGranteeType(byte onTheGrant, byte wanted)
/*      */   {
/*  170 */     return (wanted == 0) || (onTheGrant == wanted);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   private static String granteeName(Provisioning prov, ACL.Grant grant)
/*      */     throws ServiceException
/*      */   {
/*  179 */     String granteeId = grant.getGranteeId();
/*  180 */     byte granteeType = grant.getGranteeType();
/*      */     
/*  182 */     String granteeName = "";
/*  183 */     if (granteeType == 1) {
/*  184 */       Account acct = prov.get(Key.AccountBy.id, granteeId);
/*  185 */       if (acct != null)
/*  186 */         granteeName = acct.getName();
/*  187 */     } else if (granteeType == 2) {
/*  188 */       Group group = prov.getGroupBasic(Key.DistributionListBy.id, granteeId);
/*  189 */       if (group != null)
/*  190 */         granteeName = group.getName();
/*  191 */     } else if (granteeType == 5) {
/*  192 */       Cos cos = prov.get(Key.CosBy.id, granteeId);
/*  193 */       if (cos != null)
/*  194 */         granteeName = cos.getName();
/*  195 */     } else if (granteeType == 4) {
/*  196 */       Domain domain = prov.get(Key.DomainBy.id, granteeId);
/*  197 */       if (domain != null) {
/*  198 */         granteeName = domain.getName();
/*      */       }
/*      */     } else {
/*  201 */       granteeName = ACL.typeToString(granteeType);
/*      */     }
/*  203 */     return granteeName;
/*      */   }
/*      */   
/*      */   private static String granteeDisplay(Provisioning prov, ACL.Grant grant) throws ServiceException {
/*  207 */     String granteeId = grant.getGranteeId();
/*  208 */     byte granteeType = grant.getGranteeType();
/*      */     
/*  210 */     String granteeDisplay = "";
/*  211 */     if (granteeType == 1) {
/*  212 */       Account acct = prov.get(Key.AccountBy.id, granteeId);
/*  213 */       if (acct != null)
/*  214 */         granteeDisplay = acct.getDisplayName();
/*  215 */     } else if (granteeType == 2) {
/*  216 */       Group group = prov.getGroupBasic(Key.DistributionListBy.id, granteeId);
/*  217 */       if (group != null)
/*  218 */         granteeDisplay = group.getDisplayName();
/*  219 */     } else if (granteeType == 5) {
/*  220 */       Cos cos = prov.get(Key.CosBy.id, granteeId);
/*  221 */       if (cos != null)
/*  222 */         granteeDisplay = cos.getName();
/*  223 */     } else if (granteeType == 4) {
/*  224 */       Domain domain = prov.get(Key.DomainBy.id, granteeId);
/*  225 */       if (domain != null) {
/*  226 */         granteeDisplay = domain.getName();
/*      */       }
/*      */     } else {
/*  229 */       granteeDisplay = ACL.typeToString(granteeType);
/*      */     }
/*  231 */     return granteeDisplay;
/*      */   }
/*      */   
/*      */   private static Set<Folder> getVisibleFolders(OperationContext octxt, Mailbox mbox)
/*      */     throws ServiceException
/*      */   {
/*  237 */     Set<Folder> folders = mbox.getVisibleFolders(octxt);
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  243 */     if (folders == null) {
/*  244 */       Mailbox.FolderNode root = mbox.getFolderTree(octxt, null, false);
/*      */       
/*  246 */       folders = flattenAndSortFolderTree(root);
/*      */     }
/*  248 */     return folders;
/*      */   }
/*      */   
/*      */   private static Set<Folder> flattenAndSortFolderTree(Mailbox.FolderNode root) {
/*  252 */     Set<Folder> folders = new HashSet();
/*  253 */     flattenAndSortFolderTree(root, folders);
/*  254 */     return folders;
/*      */   }
/*      */   
/*      */   private static void flattenAndSortFolderTree(Mailbox.FolderNode node, Set<Folder> flattened) {
/*  258 */     if (node.mFolder != null)
/*  259 */       flattened.add(node.mFolder);
/*  260 */     for (Mailbox.FolderNode subNode : node.mSubfolders) {
/*  261 */       flattenAndSortFolderTree(subNode, flattened);
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public static class MountedFolders
/*      */   {
/*      */     private final Map<String, Integer> mMountedFolders;
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     public MountedFolders(OperationContext octxt, Account acct)
/*      */       throws ServiceException
/*      */     {
/*  280 */       this.mMountedFolders = getLocalMountpoints(octxt, acct);
/*      */     }
/*      */     
/*      */     public Integer getLocalFolderId(String ownerAcctId, int remoteFolderId) {
/*  284 */       if (this.mMountedFolders == null) {
/*  285 */         return null;
/*      */       }
/*  287 */       String key = getKey(ownerAcctId, remoteFolderId);
/*  288 */       return (Integer)this.mMountedFolders.get(key);
/*      */     }
/*      */     
/*      */     private String getKey(String ownerAcctId, int remoteFolderId)
/*      */     {
/*  293 */       return ownerAcctId + ":" + remoteFolderId;
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     private Map<String, Integer> getLocalMountpoints(OperationContext octxt, Account acct)
/*      */       throws ServiceException
/*      */     {
/*  307 */       if (octxt == null) {
/*  308 */         return null;
/*      */       }
/*  310 */       Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct, false);
/*  311 */       if (mbox == null) {
/*  312 */         throw ServiceException.FAILURE("mailbox not found for account " + acct.getId(), null);
/*      */       }
/*  314 */       return getLocalMountpoints(octxt, mbox);
/*      */     }
/*      */     
/*      */     private Map<String, Integer> getLocalMountpoints(OperationContext octxt, Mailbox mbox)
/*      */       throws ServiceException
/*      */     {
/*  320 */       Map<String, Integer> mountpoints = new HashMap();
/*      */       
/*  322 */       mbox.lock.lock(false);
/*      */       try
/*      */       {
/*  325 */         int folderId = 1;
/*  326 */         Folder folder = mbox.getFolderById(octxt, folderId);
/*      */         
/*      */ 
/*  329 */         Set<Folder> visibleFolders = mbox.getVisibleFolders(octxt);
/*  330 */         getLocalMountpoints(folder, visibleFolders, mountpoints);
/*      */       } finally {
/*  332 */         mbox.lock.release();
/*      */       }
/*      */       
/*  335 */       return mountpoints;
/*      */     }
/*      */     
/*      */     private void getLocalMountpoints(Folder folder, Set<Folder> visible, Map<String, Integer> mountpoints) throws ServiceException {
/*  339 */       boolean isVisible = (visible == null) || (visible.remove(folder));
/*  340 */       if (!isVisible) {
/*  341 */         return;
/*      */       }
/*  343 */       if ((folder instanceof Mountpoint)) {
/*  344 */         Mountpoint mpt = (Mountpoint)folder;
/*  345 */         String mid = getKey(mpt.getOwnerId(), mpt.getRemoteId());
/*  346 */         mountpoints.put(mid, Integer.valueOf(mpt.getId()));
/*      */       }
/*      */       
/*      */ 
/*  350 */       if ((visible != null) && (visible.isEmpty())) {
/*  351 */         return;
/*      */       }
/*      */       
/*  354 */       for (Folder subfolder : folder.getSubfolders(null)) {
/*  355 */         getLocalMountpoints(subfolder, visible, mountpoints);
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public static class Discover
/*      */     extends ShareInfo
/*      */   {
/*      */     public static void discover(OperationContext octxt, Provisioning prov, Account targetAcct, byte granteeType, Account ownerAcct, Provisioning.PublishedShareInfoVisitor visitor)
/*      */       throws ServiceException
/*      */     {
/*  371 */       Mailbox ownerMbox = MailboxManager.getInstance().getMailboxByAccount(ownerAcct, false);
/*  372 */       if (ownerMbox == null) {
/*  373 */         throw ServiceException.FAILURE("mailbox not found for account " + ownerAcct.getId(), null);
/*      */       }
/*  375 */       Set<Folder> folders = ShareInfo.getVisibleFolders(octxt, ownerMbox);
/*  376 */       for (Folder folder : folders) {
/*  377 */         doDiscover(prov, targetAcct, granteeType, ownerAcct, folder, visitor);
/*      */       }
/*      */     }
/*      */     
/*      */     private static void doDiscover(Provisioning prov, Account targetAcct, byte granteeType, Account ownerAcct, Folder folder, Provisioning.PublishedShareInfoVisitor visitor)
/*      */       throws ServiceException
/*      */     {
/*  384 */       ACL acl = folder.getEffectiveACL();
/*      */       
/*  386 */       if (acl == null) {
/*  387 */         return;
/*      */       }
/*  389 */       for (ACL.Grant grant : acl.getGrants()) {
/*  390 */         if (((targetAcct == null) || (grant.matches(targetAcct))) && (ShareInfo.matchesGranteeType(grant.getGranteeType(), granteeType)))
/*      */         {
/*  392 */           ShareInfo si = new ShareInfo();
/*      */           
/*  394 */           si.mData.setOwnerAcctId(ownerAcct.getId());
/*  395 */           si.mData.setOwnerAcctEmail(ownerAcct.getName());
/*  396 */           si.mData.setOwnerAcctDisplayName(ownerAcct.getDisplayName());
/*  397 */           si.mData.setItemId(folder.getId());
/*  398 */           si.mData.setItemUuid(folder.getUuid());
/*  399 */           si.mData.setPath(folder.getPath());
/*  400 */           si.mData.setFolderDefaultView(folder.getDefaultView());
/*  401 */           si.mData.setRights(grant.getGrantedRights());
/*  402 */           si.mData.setGranteeType(grant.getGranteeType());
/*  403 */           si.mData.setGranteeId(grant.getGranteeId());
/*  404 */           si.mData.setGranteeName(ShareInfo.granteeName(prov, grant));
/*  405 */           si.mData.setGranteeDisplayName(ShareInfo.granteeDisplay(prov, grant));
/*      */           
/*  407 */           visitor.visit(si.mData);
/*      */         }
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public static class Published
/*      */     extends ShareInfo
/*      */   {
/*      */     public static void get(Provisioning prov, Account acct, byte granteeType, Account owner, Provisioning.PublishedShareInfoVisitor visitor)
/*      */       throws ServiceException
/*      */     {
/*  433 */       List<String> granteeIds = new LinkedList();
/*  434 */       boolean includePublicShares = false;
/*  435 */       boolean includeAllAuthedShares = false;
/*  436 */       String guestAcctDomainId = null;
/*  437 */       if (granteeType == 0)
/*      */       {
/*  439 */         granteeIds.add(acct.getId());
/*  440 */         Provisioning.GroupMembership aclGroups = prov.getGroupMembership(acct, false);
/*  441 */         granteeIds.addAll(aclGroups.groupIds());
/*  442 */         granteeIds.add(prov.getDomain(acct).getId());
/*  443 */         Cos cos = prov.getCOS(acct);
/*  444 */         if (cos != null) {
/*  445 */           granteeIds.add(cos.getId());
/*      */         }
/*  447 */         includePublicShares = true;
/*  448 */         includeAllAuthedShares = true;
/*      */       }
/*  450 */       else if (granteeType == 1) {
/*  451 */         granteeIds.add(acct.getId());
/*      */       }
/*  453 */       else if (granteeType == 2) {
/*  454 */         Provisioning.GroupMembership aclGroups = prov.getGroupMembership(acct, false);
/*  455 */         granteeIds.addAll(aclGroups.groupIds());
/*      */       }
/*  457 */       else if ((granteeType == 7) && (acct.isIsExternalVirtualAccount())) {
/*  458 */         granteeIds.add(acct.getExternalUserMailAddress());
/*  459 */         guestAcctDomainId = prov.getDomain(acct).getId();
/*      */       }
/*  461 */       else if (granteeType == 6) {
/*  462 */         includePublicShares = true;
/*      */       }
/*  464 */       else if (granteeType == 4) {
/*  465 */         granteeIds.add(prov.getDomain(acct).getId());
/*      */       }
/*  467 */       else if (granteeType == 5) {
/*  468 */         Cos cos = prov.getCOS(acct);
/*  469 */         if (cos != null) {
/*  470 */           granteeIds.add(cos.getId());
/*      */         }
/*      */       }
/*  473 */       else if (granteeType == 3) {
/*  474 */         includeAllAuthedShares = true;
/*      */       }
/*      */       else {
/*  477 */         throw ServiceException.INVALID_REQUEST("unsupported grantee type: " + ACL.typeToString(granteeType), null);
/*      */       }
/*      */       
/*      */ 
/*  481 */       getSharesPublished(prov, visitor, owner, granteeIds, includePublicShares, includeAllAuthedShares, guestAcctDomainId);
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */     public static void getPublished(Provisioning prov, DistributionList dl, boolean directOnly, Account owner, Provisioning.PublishedShareInfoVisitor visitor)
/*      */       throws ServiceException
/*      */     {
/*  489 */       List<String> granteeIds = new LinkedList();
/*  490 */       granteeIds.add(dl.getId());
/*  491 */       if (!directOnly) {
/*  492 */         granteeIds.addAll(prov.getGroupMembership(dl, false).groupIds());
/*      */       }
/*  494 */       getSharesPublished(prov, visitor, owner, granteeIds, false, false, null);
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */     private static void getSharesPublished(Provisioning prov, Provisioning.PublishedShareInfoVisitor visitor, Account owner, List<String> granteeIds, boolean includePublicShares, boolean includeAllAuthedShares, String guestAcctDomainId)
/*      */       throws ServiceException
/*      */     {
/*  502 */       if ((granteeIds.isEmpty()) && (!includePublicShares) && (!includeAllAuthedShares)) {
/*  503 */         return;
/*      */       }
/*      */       
/*  506 */       SearchAccountsOptions searchOpts = new SearchAccountsOptions(new String[] { "zimbraId", "displayName", "zimbraSharedItem", "zimbraAccountStatus" });
/*      */       
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  512 */       searchOpts.setFilter(ZLdapFilterFactory.getInstance().accountsByGrants(granteeIds, includePublicShares, includeAllAuthedShares));
/*      */       
/*  514 */       List<NamedEntry> accounts = prov.searchDirectory(searchOpts);
/*      */       
/*      */ 
/*  517 */       for (NamedEntry ne : accounts) {
/*  518 */         Account account = (Account)ne;
/*  519 */         if (((owner == null) || 
/*  520 */           (owner.getId().equals(account.getId()))) && (
/*      */           
/*      */ 
/*      */ 
/*  524 */           (guestAcctDomainId == null) || (guestAcctDomainId.equals(prov.getDomain(account).getId()))))
/*      */         {
/*      */ 
/*  527 */           ZAttrProvisioning.AccountStatus status = account.getAccountStatus();
/*  528 */           if ((status == null) || (status.isActive()))
/*      */           {
/*      */ 
/*  531 */             String[] sharedItems = account.getSharedItem();
/*  532 */             for (String sharedItem : sharedItems) {
/*  533 */               ShareInfoData shareData = AclPushSerializer.deserialize(sharedItem);
/*  534 */               if ((!shareData.isExpired()) && ((granteeIds.contains(shareData.getGranteeId())) || ((includePublicShares) && (shareData.getGranteeTypeCode() == 6)) || ((includeAllAuthedShares) && (shareData.getGranteeTypeCode() == 3))))
/*      */               {
/*      */ 
/*      */ 
/*  538 */                 shareData.setOwnerAcctId(account.getId());
/*  539 */                 shareData.setOwnerAcctEmail(account.getName());
/*  540 */                 shareData.setOwnerAcctDisplayName(account.getDisplayName());
/*  541 */                 visitor.visit(shareData);
/*      */               }
/*      */             }
/*      */           }
/*      */         }
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public static class NotificationSender
/*      */   {
/*      */     private static final short ROLE_VIEW = 1;
/*      */     
/*      */ 
/*      */ 
/*      */     private static final short ROLE_ADMIN = 287;
/*      */     
/*      */ 
/*      */ 
/*      */     private static final short ROLE_MANAGER = 31;
/*      */     
/*      */ 
/*      */ 
/*      */     private static final String HTML_LINE_BREAK = "<br>";
/*      */     
/*      */ 
/*      */ 
/*      */     private static final String NEWLINE = "\n";
/*      */     
/*      */ 
/*      */ 
/*      */     public static MimeMultipart genNotifBody(ShareInfoData sid, String notes, Locale locale, SendShareNotificationRequest.Action action, String externalGroupMember)
/*      */       throws MessagingException, ServiceException
/*      */     {
/*  578 */       MimeMultipart mmp = new ZMimeMultipart("alternative");
/*      */       
/*  580 */       String extUserShareAcceptUrl = null;
/*  581 */       String extUserLoginUrl = null;
/*  582 */       String externalGranteeName = null;
/*  583 */       if (sid.getGranteeTypeCode() == 7) {
/*  584 */         externalGranteeName = sid.getGranteeName();
/*  585 */       } else if ((sid.getGranteeTypeCode() == 2) && (externalGroupMember != null)) {
/*  586 */         externalGranteeName = externalGroupMember;
/*      */       }
/*      */       
/*  589 */       boolean goesToExternalAddr = externalGranteeName != null;
/*  590 */       if ((action == null) && (goesToExternalAddr)) {
/*  591 */         Account owner = Provisioning.getInstance().getAccountById(sid.getOwnerAcctId());
/*  592 */         extUserShareAcceptUrl = getShareAcceptURL(owner, sid.getItemId(), externalGranteeName);
/*  593 */         extUserLoginUrl = getExtUserLoginURL(owner);
/*      */       }
/*      */       
/*      */       String mimePartText;
/*      */       String mimePartText;
/*  598 */       if (action == SendShareNotificationRequest.Action.revoke) {
/*  599 */         mimePartText = genRevokePart(sid, locale, false); } else { String mimePartText;
/*  600 */         if (action == SendShareNotificationRequest.Action.expire) {
/*  601 */           mimePartText = genExpirePart(sid, locale, false);
/*      */         } else {
/*  603 */           mimePartText = genPart(sid, action == SendShareNotificationRequest.Action.edit, notes, extUserShareAcceptUrl, extUserLoginUrl, locale, null, false);
/*      */         }
/*      */       }
/*  606 */       MimeBodyPart textPart = new ZMimeBodyPart();
/*  607 */       textPart.setText(mimePartText, "utf-8");
/*  608 */       mmp.addBodyPart(textPart);
/*      */       
/*      */ 
/*  611 */       if (action == SendShareNotificationRequest.Action.revoke) {
/*  612 */         mimePartText = genRevokePart(sid, locale, true);
/*  613 */       } else if (action == SendShareNotificationRequest.Action.expire) {
/*  614 */         mimePartText = genExpirePart(sid, locale, true);
/*      */       } else {
/*  616 */         mimePartText = genPart(sid, action == SendShareNotificationRequest.Action.edit, notes, extUserShareAcceptUrl, extUserLoginUrl, locale, null, true);
/*      */       }
/*      */       
/*  619 */       MimeBodyPart htmlPart = new ZMimeBodyPart();
/*  620 */       htmlPart.setDataHandler(new DataHandler(new HtmlPartDataSource(mimePartText)));
/*  621 */       mmp.addBodyPart(htmlPart);
/*      */       
/*      */ 
/*  624 */       if (!goesToExternalAddr) {
/*  625 */         MimeBodyPart xmlPart = new ZMimeBodyPart();
/*  626 */         xmlPart.setDataHandler(new DataHandler(new XmlPartDataSource(genXmlPart(sid, notes, null, action))));
/*      */         
/*  628 */         mmp.addBodyPart(xmlPart);
/*      */       }
/*      */       
/*  631 */       return mmp;
/*      */     }
/*      */     
/*      */     private static String getExtUserLoginURL(Account owner) throws ServiceException {
/*  635 */       return ZimbraServlet.getServiceUrl(owner.getServer(), Provisioning.getInstance().getDomain(owner), "?virtualacctdomain=" + owner.getDomainName());
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */     private static String getShareAcceptURL(Account account, int folderId, String externalUserEmail)
/*      */       throws ServiceException
/*      */     {
/*  643 */       StringBuilder encodedBuff = new StringBuilder();
/*  644 */       BlobMetaData.encodeMetaData("aid", account.getId(), encodedBuff);
/*  645 */       BlobMetaData.encodeMetaData("fid", folderId, encodedBuff);
/*  646 */       BlobMetaData.encodeMetaData("email", externalUserEmail, encodedBuff);
/*  647 */       Domain domain = Provisioning.getInstance().getDomain(account);
/*  648 */       if (domain != null) {
/*  649 */         long urlExpiration = domain.getExternalShareInvitationUrlExpiration();
/*  650 */         if (urlExpiration != 0L) {
/*  651 */           BlobMetaData.encodeMetaData("exp", System.currentTimeMillis() + urlExpiration, encodedBuff);
/*      */         }
/*      */       }
/*  654 */       String data = new String(Hex.encodeHex(encodedBuff.toString().getBytes()));
/*  655 */       ExtAuthTokenKey key = ExtAuthTokenKey.getCurrentKey();
/*  656 */       String hmac = ZimbraAuthToken.getHmac(data, key.getKey());
/*  657 */       String encoded = key.getVersion() + "_" + hmac + "_" + data;
/*  658 */       String path = "/service/extuserprov/?p=" + encoded;
/*  659 */       return ZimbraServlet.getServiceUrl(account.getServer(), Provisioning.getInstance().getDomain(account), path);
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */     private static String genPart(ShareInfoData sid, boolean shareModified, String senderNotes, String extUserShareAcceptUrl, String extUserLoginUrl, Locale locale, StringBuilder sb, boolean html)
/*      */     {
/*  666 */       if (sb == null) {
/*  667 */         sb = new StringBuilder();
/*      */       }
/*  669 */       String externalShareInfo = null;
/*  670 */       if (extUserShareAcceptUrl != null) {
/*  671 */         assert (extUserLoginUrl != null);
/*  672 */         externalShareInfo = L10nUtil.getMessage(html ? L10nUtil.MsgKey.shareNotifBodyExternalShareHtml : L10nUtil.MsgKey.shareNotifBodyExternalShareText, locale, new Object[] { extUserShareAcceptUrl, extUserLoginUrl });
/*      */       }
/*      */       
/*      */ 
/*  676 */       if (!Strings.isNullOrEmpty(senderNotes)) {
/*  677 */         if (!html) {
/*  678 */           senderNotes = L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyNotesText, locale, new Object[] { senderNotes });
/*      */         }
/*      */         else {
/*  681 */           senderNotes = senderNotes.replaceAll("\n", "<br>");
/*  682 */           senderNotes = L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyNotesHtml, locale, new Object[] { senderNotes });
/*      */         }
/*      */       }
/*      */       L10nUtil.MsgKey msgKey;
/*      */       L10nUtil.MsgKey msgKey;
/*  687 */       if (shareModified) {
/*  688 */         msgKey = html ? L10nUtil.MsgKey.shareModifyBodyHtml : L10nUtil.MsgKey.shareModifyBodyText;
/*      */       } else {
/*  690 */         msgKey = html ? L10nUtil.MsgKey.shareNotifBodyHtml : L10nUtil.MsgKey.shareNotifBodyText;
/*      */       }
/*  692 */       return L10nUtil.getMessage(msgKey, locale, new Object[] { sid.getName(), formatFolderDesc(locale, sid), sid.getOwnerNotifName(), sid.getGranteeNotifName(), getRoleFromRights(sid, locale), getRightsText(sid, locale), Strings.nullToEmpty(externalShareInfo), Strings.nullToEmpty(senderNotes) });
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     private static String genRevokePart(ShareInfoData sid, Locale locale, boolean html)
/*      */     {
/*  706 */       return L10nUtil.getMessage(html ? L10nUtil.MsgKey.shareRevokeBodyHtml : L10nUtil.MsgKey.shareRevokeBodyText, new Object[] { sid.getName(), formatFolderDesc(locale, sid), sid.getOwnerNotifName() });
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */     private static String genExpirePart(ShareInfoData sid, Locale locale, boolean html)
/*      */     {
/*  713 */       return L10nUtil.getMessage(html ? L10nUtil.MsgKey.shareExpireBodyHtml : L10nUtil.MsgKey.shareExpireBodyText, new Object[] { sid.getName(), formatFolderDesc(locale, sid), sid.getOwnerNotifName() });
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */     private static String genXmlPart(ShareInfoData sid, String senderNotes, StringBuilder sb, SendShareNotificationRequest.Action action)
/*      */       throws ServiceException
/*      */     {
/*  721 */       if (sb == null)
/*  722 */         sb = new StringBuilder();
/*      */       Element share;
/*      */       Element share;
/*  725 */       if ((action == null) || (action == SendShareNotificationRequest.Action.edit)) {
/*  726 */         share = Element.create(SoapProtocol.Soap12, MailConstants.ShareConstants.SHARE).addAttribute("version", "0.2").addAttribute("action", action == null ? "new" : "edit");
/*      */ 
/*      */       }
/*      */       else
/*      */       {
/*  731 */         share = Element.create(SoapProtocol.Soap12, MailConstants.ShareConstants.REVOKE).addAttribute("version", "0.2");
/*      */         
/*  733 */         if (action == SendShareNotificationRequest.Action.expire) {
/*  734 */           share.addAttribute("expire", true);
/*      */         }
/*      */       }
/*  737 */       share.addElement("grantee").addAttribute("id", sid.getGranteeId()).addAttribute("email", sid.getGranteeName()).addAttribute("name", sid.getGranteeNotifName());
/*      */       
/*      */ 
/*      */ 
/*  741 */       share.addElement("grantor").addAttribute("id", sid.getOwnerAcctId()).addAttribute("email", sid.getOwnerAcctEmail()).addAttribute("name", sid.getOwnerNotifName());
/*      */       
/*      */ 
/*      */ 
/*  745 */       Element link = share.addElement("link");
/*  746 */       link.addAttribute("id", sid.getItemId()).addAttribute("name", sid.getName()).addAttribute("view", sid.getFolderDefaultView());
/*      */       
/*      */ 
/*  749 */       if ((action == null) || (action == SendShareNotificationRequest.Action.edit)) {
/*  750 */         link.addAttribute("perm", ACL.rightsToString(sid.getRightsCode()));
/*      */       }
/*  752 */       sb.append(share.prettyPrint());
/*  753 */       return sb.toString();
/*      */     }
/*      */     
/*      */     private static void appendCommaSeparated(StringBuffer sb, String s) {
/*  757 */       if (sb.length() > 0)
/*  758 */         sb.append(", ");
/*  759 */       sb.append(s);
/*      */     }
/*      */     
/*      */     private static String getRoleFromRights(ShareInfoData sid, Locale locale) {
/*  763 */       String rights = sid.getRights();
/*  764 */       rights = rights.replace(ACL.rightsToString((short)1024), "");
/*  765 */       if (rights.equals(ACL.rightsToString((short)287)))
/*  766 */         return L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyGranteeRoleAdmin, locale, new Object[0]);
/*  767 */       if (rights.equals(ACL.rightsToString((short)31)))
/*  768 */         return L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyGranteeRoleManager, locale, new Object[0]);
/*  769 */       if (rights.equals(ACL.rightsToString((short)1)))
/*  770 */         return L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyGranteeRoleViewer, locale, new Object[0]);
/*  771 */       if (StringUtil.isNullOrEmpty(sid.getRights())) {
/*  772 */         return L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyGranteeRoleNone, locale, new Object[0]);
/*      */       }
/*  774 */       return L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyGranteeRoleCustom, locale, new Object[0]);
/*      */     }
/*      */     
/*      */     private static String getRightsText(ShareInfoData sid, Locale locale)
/*      */     {
/*  779 */       short rights = sid.getRightsCode();
/*  780 */       StringBuffer r = new StringBuffer();
/*  781 */       if ((rights & 0x1) != 0) appendCommaSeparated(r, L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyActionRead, locale, new Object[0]));
/*  782 */       if ((rights & 0x2) != 0) appendCommaSeparated(r, L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyActionWrite, locale, new Object[0]));
/*  783 */       if ((rights & 0x4) != 0) appendCommaSeparated(r, L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyActionInsert, locale, new Object[0]));
/*  784 */       if ((rights & 0x8) != 0) appendCommaSeparated(r, L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyActionDelete, locale, new Object[0]));
/*  785 */       if ((rights & 0x100) != 0) appendCommaSeparated(r, L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyActionAdmin, locale, new Object[0]));
/*  786 */       if (r.toString().isEmpty()) {
/*  787 */         return L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyActionNone, locale, new Object[0]);
/*      */       }
/*  789 */       return r.toString();
/*      */     }
/*      */     
/*      */     private static String formatFolderDesc(Locale locale, ShareInfoData sid)
/*      */     {
/*  794 */       MailItem.Type view = sid.getFolderDefaultViewCode();
/*      */       String folderView;
/*  796 */       switch (ShareInfo.1.$SwitchMap$com$zimbra$cs$mailbox$MailItem$Type[view.ordinal()]) {
/*      */       case 1: 
/*  798 */         folderView = L10nUtil.getMessage(L10nUtil.MsgKey.mail, locale, new Object[0]);
/*  799 */         break;
/*      */       case 2: 
/*  801 */         folderView = L10nUtil.getMessage(L10nUtil.MsgKey.calendar, locale, new Object[0]);
/*  802 */         break;
/*      */       case 3: 
/*  804 */         folderView = L10nUtil.getMessage(L10nUtil.MsgKey.task, locale, new Object[0]);
/*  805 */         break;
/*      */       case 4: 
/*  807 */         folderView = L10nUtil.getMessage(L10nUtil.MsgKey.addressBook, locale, new Object[0]);
/*  808 */         break;
/*      */       case 5: 
/*  810 */         folderView = L10nUtil.getMessage(L10nUtil.MsgKey.briefcase, locale, new Object[0]);
/*  811 */         break;
/*      */       default: 
/*  813 */         folderView = sid.getFolderDefaultView();
/*      */       }
/*  815 */       L10nUtil.MsgKey key = L10nUtil.MsgKey.shareNotifBodyFolderDesc;
/*      */       try {
/*  817 */         if (Provisioning.getInstance().isOctopus()) {
/*  818 */           key = L10nUtil.MsgKey.octopus_share_notification_email_bodyFolderDesc;
/*      */         }
/*      */       } catch (ServiceException e) {
/*  821 */         ZimbraLog.account.warn("failed to retrieve Octopus info from LDAP " + e);
/*      */       }
/*  823 */       return L10nUtil.getMessage(key, locale, new Object[] { folderView });
/*      */     }
/*      */     
/*      */     private static class MailSenderVisitor implements Provisioning.PublishedShareInfoVisitor
/*      */     {
/*  828 */       List<ShareInfoData> mShares = new ArrayList();
/*      */       
/*      */       public void visit(ShareInfoData sid) throws ServiceException
/*      */       {
/*  832 */         this.mShares.add(sid);
/*      */       }
/*      */       
/*      */       private int getNumShareInfo() {
/*  836 */         return this.mShares.size();
/*      */       }
/*      */       
/*      */       private String genText(String dlName, Locale locale, Integer idx) {
/*  840 */         StringBuilder sb = new StringBuilder();
/*      */         
/*  842 */         sb.append("\n");
/*  843 */         sb.append(L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyAddedToGroup1, locale, new Object[] { dlName }));
/*  844 */         sb.append("\n\n");
/*  845 */         sb.append(L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyAddedToGroup2, locale, new Object[] { dlName }));
/*  846 */         sb.append("\n\n");
/*      */         
/*  848 */         if (idx == null) {
/*  849 */           for (ShareInfoData sid : this.mShares) {
/*  850 */             ShareInfo.NotificationSender.genPart(sid, false, null, null, null, locale, sb, false);
/*      */           }
/*      */         } else {
/*  853 */           ShareInfo.NotificationSender.genPart((ShareInfoData)this.mShares.get(idx.intValue()), false, null, null, null, locale, sb, false);
/*      */         }
/*  855 */         sb.append("\n\n");
/*  856 */         return sb.toString();
/*      */       }
/*      */       
/*      */       private String genHtml(String dlName, Locale locale, Integer idx)
/*      */       {
/*  861 */         StringBuilder sb = new StringBuilder();
/*      */         
/*  863 */         sb.append("<h4>\n");
/*  864 */         sb.append("<p>" + L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyAddedToGroup1, locale, new Object[] { dlName }) + "</p>\n");
/*  865 */         sb.append("<p>" + L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifBodyAddedToGroup2, locale, new Object[] { dlName }) + "</p>\n");
/*  866 */         sb.append("</h4>\n");
/*  867 */         sb.append("\n");
/*      */         
/*  869 */         if (idx == null) {
/*  870 */           for (ShareInfoData sid : this.mShares) {
/*  871 */             ShareInfo.NotificationSender.genPart(sid, false, null, null, null, locale, sb, true);
/*      */           }
/*      */         } else {
/*  874 */           ShareInfo.NotificationSender.genPart((ShareInfoData)this.mShares.get(idx.intValue()), false, null, null, null, locale, sb, true);
/*      */         }
/*  876 */         return sb.toString();
/*      */       }
/*      */       
/*      */       private String genXml(Integer idx) throws ServiceException {
/*  880 */         StringBuilder sb = new StringBuilder();
/*      */         
/*  882 */         if (idx == null) {
/*  883 */           for (ShareInfoData sid : this.mShares) {
/*  884 */             ShareInfo.NotificationSender.genXmlPart(sid, null, sb, null);
/*      */           }
/*      */         } else {
/*  887 */           ShareInfo.NotificationSender.genXmlPart((ShareInfoData)this.mShares.get(idx.intValue()), null, sb, null);
/*      */         }
/*  889 */         return sb.toString();
/*      */       }
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     private static boolean sendOneMailPerShare()
/*      */     {
/*  901 */       return true;
/*      */     }
/*      */     
/*      */     public static void sendShareInfoMessage(OperationContext octxt, DistributionList dl, String[] members)
/*      */     {
/*  906 */       Provisioning prov = Provisioning.getInstance();
/*  907 */       Account authedAcct = octxt.getAuthenticatedUser();
/*      */       
/*  909 */       MailSenderVisitor visitor = new MailSenderVisitor(null);
/*      */       try
/*      */       {
/*  912 */         ShareInfo.Published.getPublished(prov, dl, false, null, visitor);
/*      */       } catch (ServiceException e) {
/*  914 */         ZimbraLog.account.warn("failed to retrieve share info for dl: " + dl.getName(), e);
/*  915 */         return;
/*      */       }
/*      */       
/*      */ 
/*  919 */       if (visitor.getNumShareInfo() == 0) {
/*  920 */         return;
/*      */       }
/*  922 */       for (String member : members) {
/*      */         try
/*      */         {
/*  925 */           sendMessage(prov, authedAcct, dl, member, visitor);
/*      */         } catch (MessagingException e) {
/*  927 */           ZimbraLog.account.warn("failed to send share info message", e);
/*      */         } catch (ServiceException e) {
/*  929 */           ZimbraLog.account.warn("failed to send share info message", e);
/*      */         }
/*      */       }
/*      */     }
/*      */     
/*      */     private static Locale getLocale(Provisioning prov, Account fromAcct, String toAddr) throws ServiceException
/*      */     {
/*  936 */       Account rcptAcct = prov.get(Key.AccountBy.name, toAddr);
/*  937 */       Locale locale; Locale locale; if (rcptAcct != null) {
/*  938 */         locale = rcptAcct.getLocale(); } else { Locale locale;
/*  939 */         if (fromAcct != null) {
/*  940 */           locale = fromAcct.getLocale();
/*      */         } else
/*  942 */           locale = prov.getConfig().getLocale();
/*      */       }
/*  944 */       return locale;
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     private static Pair<Address, Address> getFromAndReplyToAddr(Account fromAcct, DistributionList dl)
/*      */       throws AddressException
/*      */     {
/*  958 */       String dlssmfa = dl.getAttr("zimbraDistributionListSendShareMessageFromAddress");
/*      */       try {
/*  960 */         if (dlssmfa != null) {
/*  961 */           InternetAddress addr = new JavaMailInternetAddress(dlssmfa);
/*  962 */           return new Pair(addr, addr);
/*      */         }
/*      */       }
/*      */       catch (AddressException e) {
/*  966 */         ZimbraLog.account.warn("invalid address in zimbraDistributionListSendShareMessageFromAddress on distribution list entry " + dl.getName() + ", ignored", e);
/*      */       }
/*      */       
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  973 */       if (fromAcct != null) {
/*  974 */         InternetAddress addr = AccountUtil.getFriendlyEmailAddress(fromAcct);
/*      */         try
/*      */         {
/*  977 */           addr.validate();
/*      */           
/*  979 */           Address replyToAddr = addr;
/*  980 */           String replyTo = fromAcct.getAttr("zimbraPrefReplyToAddress");
/*  981 */           if (replyTo != null)
/*  982 */             replyToAddr = new JavaMailInternetAddress(replyTo);
/*  983 */           return new Pair(addr, replyToAddr);
/*      */         }
/*      */         catch (AddressException ignored) {}
/*      */       }
/*      */       
/*      */ 
/*  989 */       InternetAddress addr = new JavaMailInternetAddress(dl.getName());
/*  990 */       return new Pair(addr, addr);
/*      */     }
/*      */     
/*      */     private static MimeMultipart buildMailContent(DistributionList dl, MailSenderVisitor visitor, Locale locale, Integer idx)
/*      */       throws MessagingException, ServiceException
/*      */     {
/*  996 */       String shareInfoText = visitor.genText(dl.getName(), locale, idx);
/*  997 */       String shareInfoHtml = visitor.genHtml(dl.getName(), locale, idx);
/*  998 */       String shareInfoXml = null;
/*  999 */       if (idx != null) {
/* 1000 */         shareInfoXml = visitor.genXml(idx);
/*      */       }
/*      */       
/* 1003 */       MimeMultipart mmp = new ZMimeMultipart("alternative");
/*      */       
/*      */ 
/* 1006 */       MimeBodyPart textPart = new ZMimeBodyPart();
/* 1007 */       textPart.setText(shareInfoText, "utf-8");
/* 1008 */       mmp.addBodyPart(textPart);
/*      */       
/*      */ 
/* 1011 */       MimeBodyPart htmlPart = new ZMimeBodyPart();
/* 1012 */       htmlPart.setDataHandler(new DataHandler(new HtmlPartDataSource(shareInfoHtml)));
/* 1013 */       mmp.addBodyPart(htmlPart);
/*      */       
/*      */ 
/* 1016 */       if (shareInfoXml != null) {
/* 1017 */         MimeBodyPart xmlPart = new ZMimeBodyPart();
/* 1018 */         xmlPart.setDataHandler(new DataHandler(new XmlPartDataSource(shareInfoXml)));
/* 1019 */         mmp.addBodyPart(xmlPart);
/*      */       }
/*      */       
/* 1022 */       return mmp;
/*      */     }
/*      */     
/*      */     private static void buildContentAndSend(SMTPMessage out, DistributionList dl, MailSenderVisitor visitor, Locale locale, Integer idx)
/*      */       throws MessagingException, ServiceException
/*      */     {
/* 1028 */       MimeMultipart mmp = buildMailContent(dl, visitor, locale, idx);
/* 1029 */       out.setContent(mmp);
/* 1030 */       Transport.send(out);
/*      */       
/*      */ 
/* 1033 */       Address[] rcpts = out.getRecipients(Message.RecipientType.TO);
/* 1034 */       StringBuilder rcptAddr = new StringBuilder();
/* 1035 */       for (Address a : rcpts)
/* 1036 */         rcptAddr.append(a.toString());
/* 1037 */       ZimbraLog.account.info("share info notification sent rcpt='" + rcptAddr + "' Message-ID=" + out.getMessageID());
/*      */     }
/*      */     
/*      */     private static void sendMessage(Provisioning prov, Account fromAcct, DistributionList dl, String toAddr, MailSenderVisitor visitor)
/*      */       throws MessagingException, ServiceException
/*      */     {
/* 1043 */       SMTPMessage out = new SMTPMessage(JMSession.getSmtpSession());
/*      */       
/* 1045 */       Pair<Address, Address> senderAddrs = getFromAndReplyToAddr(fromAcct, dl);
/* 1046 */       Address fromAddr = (Address)senderAddrs.getFirst();
/* 1047 */       Address replyToAddr = (Address)senderAddrs.getSecond();
/*      */       
/*      */ 
/* 1050 */       out.setFrom(fromAddr);
/*      */       
/*      */ 
/* 1053 */       out.setReplyTo(new Address[] { replyToAddr });
/*      */       
/*      */ 
/* 1056 */       out.setRecipient(Message.RecipientType.TO, new JavaMailInternetAddress(toAddr));
/*      */       
/*      */ 
/* 1059 */       out.setSentDate(new Date());
/*      */       
/*      */ 
/* 1062 */       Locale locale = getLocale(prov, fromAcct, toAddr);
/* 1063 */       String subject = L10nUtil.getMessage(L10nUtil.MsgKey.shareNotifSubject, locale, new Object[0]);
/* 1064 */       out.setSubject(subject);
/*      */       
/* 1066 */       if (sendOneMailPerShare())
/*      */       {
/*      */ 
/* 1069 */         int numShareInfo = visitor.getNumShareInfo();
/* 1070 */         for (int idx = 0; idx < numShareInfo; idx++) {
/* 1071 */           buildContentAndSend(out, dl, visitor, locale, Integer.valueOf(idx));
/*      */         }
/*      */       }
/*      */       else
/*      */       {
/* 1076 */         buildContentAndSend(out, dl, visitor, locale, null);
/*      */       }
/*      */     }
/*      */     
/*      */     private static abstract class MimePartDataSource implements DataSource
/*      */     {
/*      */       private final String mText;
/* 1083 */       private byte[] mBuf = null;
/*      */       
/*      */       public MimePartDataSource(String text) {
/* 1086 */         this.mText = text;
/*      */       }
/*      */       
/*      */       public InputStream getInputStream() throws IOException
/*      */       {
/* 1091 */         synchronized (this) {
/* 1092 */           if (this.mBuf == null) {
/* 1093 */             ByteArrayOutputStream buf = new ByteArrayOutputStream();
/* 1094 */             OutputStreamWriter wout = new OutputStreamWriter(buf, "utf-8");
/*      */             
/* 1096 */             String text = this.mText;
/* 1097 */             wout.write(text);
/* 1098 */             wout.flush();
/* 1099 */             this.mBuf = buf.toByteArray();
/*      */           }
/*      */         }
/* 1102 */         return new ByteArrayInputStream(this.mBuf);
/*      */       }
/*      */       
/*      */       public OutputStream getOutputStream()
/*      */       {
/* 1107 */         throw new UnsupportedOperationException();
/*      */       }
/*      */     }
/*      */     
/*      */     private static class HtmlPartDataSource extends ShareInfo.NotificationSender.MimePartDataSource
/*      */     {
/*      */       private static final String CONTENT_TYPE = "text/html; charset=utf-8";
/*      */       private static final String NAME = "HtmlDataSource";
/*      */       
/*      */       HtmlPartDataSource(String text) {
/* 1117 */         super();
/*      */       }
/*      */       
/*      */       public String getContentType()
/*      */       {
/* 1122 */         return "text/html; charset=utf-8";
/*      */       }
/*      */       
/*      */       public String getName()
/*      */       {
/* 1127 */         return "HtmlDataSource";
/*      */       }
/*      */     }
/*      */     
/*      */     private static class XmlPartDataSource extends ShareInfo.NotificationSender.MimePartDataSource
/*      */     {
/*      */       private static final String CONTENT_TYPE = "xml/x-zimbra-share; charset=utf-8";
/*      */       private static final String NAME = "XmlDataSource";
/*      */       
/*      */       XmlPartDataSource(String text) {
/* 1137 */         super();
/*      */       }
/*      */       
/*      */       public String getContentType()
/*      */       {
/* 1142 */         return "xml/x-zimbra-share; charset=utf-8";
/*      */       }
/*      */       
/*      */       public String getName()
/*      */       {
/* 1147 */         return "XmlDataSource";
/*      */       }
/*      */     }
/*      */   }
/*      */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ShareInfo.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */